/*
 * 
 * ....................................................................
 * ...######..#####.....##....####..#####..####..#####..######....##...
 * .....##....##..#....###...##.....##.....##....##..#....##.....###...
 * .....##....####....#.##....##....####...####..####.....##....#.##...
 * .....##....##.#...#####.....##...##.....##....##.#.....##...#####...
 * .....##....##..#.#...##..####....##.....####..##..#....##..#...##...
 * ....................................................................
 */

package ua.trasferta.common.utils;

import static ua.trasferta.common.utils.Objects.*;
import ua.trasferta.common.annotations.createBy;
import static ua.trasferta.common.team.TeamMember.*;

/**
 * <p>
 * Need to do some aweful things use the class that we call @ Strings}.<br>
 * </p>
 * 
 * @author Anton Podviaznikov
 */
@SuppressWarnings("unused")
@createBy(authors = ANTON_PODVIAZNIKOV)
public final class Strings
{
	/** Empty sting */
	public static final String EMPTY = "";
	/** {@link String} WHITESPACE_STRING = " " */
	public static final String WHITESPACE = " ";
	/**
	 * Constant for storing left bracket as char instance.<br>
	 * char LEFT_BRACE = '('
	 */
	public static final char LEFT_BRACE = '(';
	/**
	 * Constant for storing right bracket as char instance.<br>
	 * char RIGHT_BRACE = ')'
	 */
	public static final char RIGHT_BRACE = ')';
	/**
	 * Constant for storing left square bracket as char instance.<br>
	 * char LEFT_SQUARE_BREAK = '['
	 */
	public static final char LEFT_SQUARE_BREAK = '[';
	/**
	 * Constant for storing right square bracket as char instance.<br>
	 * char RIGHT_SQUARE_BREAK = ']'
	 */
	public static final char RIGHT_SQUARE_BREAK = ']';
	/**
	 * Constant for storing left curly brace as char instance.<br>
	 * char LEFT_CURLY_BRACE = '{'
	 */
	public static final char LEFT_CURLY_BRACE = '{';
	/**
	 * Constant for storing right curly brace as char instance.<br>
	 * char RIGHT_CURLY_BRACE = '}'
	 */
	public static final char RIGHT_CURLY_BRACE = '}';
	/**
	 * Constant for storing colon as char instance.<br>
	 * char COLON_CHAR = ':'
	 */
	public static final char COLON_CHAR = ':';
	/**
	 * Constant for storing minus as char instance.<br>
	 * char MINUS_CHAR = '-'
	 */
	public static final char MINUS_CHAR = '-';
	/**
	 * Constant for storing equals as char instance.<br>
	 * char EQUALS_CHAR = '='
	 */
	public static final char EQUALS_CHAR = '=';
	/**
	 * Constant for storing underscore as char instance.<br>
	 * char UNDERSCORE_CHAR = '-'
	 */
	public static final char UNDERSCORE_CHAR = '_';
	/** String with backslash and quote. {@link String} BACKSLASH_QUOTE = "\"". */
	public static final String BACKSLASH_QUOTE = "\"";
	/** Slash character. {@link String} SLASH = "/". */
	public static final char SLASH = '/';
	/** String with comma. {@link String} COMMA = ",". */
	public static final String COMMA = ",";
	/** Character S = "s". */
	public static final char S = 's';
	/**
	 * Constant for storing semicolon as char instance.<br>
	 * char SEMICOLUMN = ';'
	 */
	public static final char SEMICOLON_CHAR = ';';

	/**
	 * Private constructor to avoid class instantiation.
	 */
	private Strings()
	{
		// hidden constructor.
	}

	/**
	 * Method wraps input {@code str} with {@link Strings#BACKSLASH_QUOTE}.
	 * 
	 * @param str - {@link String} instance to be wrapped.
	 * @return wrapped {@link String} instance.
	 */
	public static String wrapStringQuotes(String str)
	{
		return Strings.wrapStringWithString(str, Strings.BACKSLASH_QUOTE);
	}

	/**
	 * Method wraps input {@code strToWrap} with another {@link String}
	 * instance.
	 * 
	 * @param str - {@link String} instance to be wrapped.
	 * @param wrapperStr - {@link String} instance used to wrap.
	 * @return wrapped {@link String} instance.
	 */
	public static String wrapStringWithString(String strToWrap, String wrapperStr)
	{
		StringBuilder builder = new StringBuilder();
		builder.append(wrapperStr).append(strToWrap).append(wrapperStr);
		return builder.toString();
	}

	/**
	 * Method for slashes inversion.
	 * 
	 * @param str - {@link String} in which slashes to be inverted.
	 * @return {@link String} instance with inverted String.
	 */
	public static String inverseSlashes(String str)
	{
		Objects.checkNotNull(str);
		return str.replace('\\', '/');
	}

	/**
	 * Method checks whether {@link String} instance is empty.
	 * 
	 * @param str - {@link String} instance to be checked.
	 * @return {@code true} if input {@link String} is empty and {@code false}
	 *         otherwise.
	 */
	public static boolean isEmpty(String str)
	{
		return (str == null) || (str.length() < 1) ? true : false;
	}

	/**
	 * Method checks whether {@link String} instance is <b>not</b> empty.
	 * 
	 * @param str - {@link String} instance to be checked.
	 * @return {@code true} if input {@link String} is not empty and {@code
	 *         false} otherwise.
	 */
	public static boolean isNotEmpty(String str)
	{
		return !Strings.isEmpty(str);
	}

	/**
	 * Method converts {@code target} to the {@code camel} case
	 * 
	 * @param target - {@link String} instance to be checked.
	 * @return {@link String} converted to the camel case.
	 */
	public static String strToCamelCase(String target)
	{
		Objects.checkNotNull(target);
		StringBuilder translation = new StringBuilder();
		for (int i = 0; i < target.length(); i++)
		{
			char character = target.charAt(i);
			if (Character.isUpperCase(character) && (translation.length() != 0))
			{
				translation.append(Strings.UNDERSCORE_CHAR);
			}
			translation.append(Character.toLowerCase(character));
		}
		return translation.toString();
	}

	/**
	 * Just reverts the string
	 * 
	 * @param toReverse hmmm... the source?
	 * @return reverted, of course
	 */
	public static String reverseString(String toReverse)
	{
		return new StringBuilder(toReverse).reverse().toString();
	}
}
